*******************************************************************************
* Load candidates data
*******************************************************************************

use dataset_candidates, clear
keep if !mi(ideology)

*******************************************************************************
* Do the regressions with population interaction
*******************************************************************************

gen lpop = log(population)
xtile qpop = lpop, nq(2)
gen deputyXqpop = deputy*qpop

eststo clear
eststo: reg ideology deputy qpop deputyXqpop, cl(district)
eststo: reg ideology deputy qpop deputyXqpop trumpvoteshare, cl(district)
eststo: areg ideology deputy qpop deputyXqpop cycle_*, cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"
eststo: areg ideology deputy qpop deputyXqpop trumpvoteshare cycle_*, cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"

*******************************************************************************
* Output
*******************************************************************************

label variable qpop "Population"
label variable deputyXqpop "Experienced X Population"
label variable deputy "Experienced"
label variable trumpvoteshare "Trump Vote Share"

#delimit;

esttab
	using "_output/tableS6_a.tex"
	,
		replace
		booktabs
		cells(b(fmt(3)) se(par) p(par("[" "]")))
		drop(cycle*) 
		stats(
			N cyclefe statefe,
			label(
				"Observations"
				"State fixed effects"
				"Cycle fixed effects"
			)
			fmt(%20.0f %20.0f)
		)
		label
		collabels(none)	
		mlabels(none)
		width(\linewidth)
		alignment(l)
		gap
		;
		
#delimit cr

*******************************************************************************
* Do the regressions with crime interaction
*******************************************************************************

gen crime = property + violent
gen crimepcp = crime/population*100000
xtile qcrime = crimepcp, nq(2)
gen deputyXqcrime = deputy*qcrime

eststo clear
eststo: reg ideology deputy qcrime deputyXqcrime, cl(district)
eststo: reg ideology deputy qcrime deputyXqcrime trumpvoteshare, cl(district)
eststo: areg ideology deputy qcrime deputyXqcrime cycle_*, cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"
eststo: areg ideology deputy qcrime deputyXqcrime trumpvoteshare cycle_*, cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"

*******************************************************************************
* Output
*******************************************************************************

label variable qcrime "Crime"
label variable deputyXqcrime "Experienced X Crime"

#delimit;

esttab
	using "_output/tableS6_b.tex"
	,
		replace
		booktabs
		cells(b(fmt(3)) se(par) p(par("[" "]")))
		drop(cycle*) 
		stats(
			N cyclefe statefe,
			label(
				"Observations"
				"State fixed effects"
				"Cycle fixed effects"
			)
			fmt(%20.0f %20.0f)
		)
		label
		collabels(none)	
		mlabels(none)
		width(\linewidth)
		alignment(l)
		gap
		;
		
#delimit cr

*******************************************************************************
* End
*******************************************************************************
